package com.hacker.spider.wallhaven;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.tuple.Pair;

public class PageInfo {

  private final String discardStr = "&page=";

  private int total;

  private String url;

  public PageInfo() {
  }

  public PageInfo(int total, String url) {
    this.total = total;
    this.url = url;
  }

  public int getTotal() {
    return total;
  }

  public void setTotal(int total) {
    this.total = total;
  }

  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  public String getBaseUrl() {
    int index = url.lastIndexOf(discardStr);
    return index == -1 ? url : url.substring(0, index);
  }

  public List<Pair<String, Integer>> buildPages() {
    List<Pair<String, Integer>> pages = new ArrayList<>(total);
    String baseUrl = getBaseUrl() + discardStr;
    for (int index = 1; index <= total; index++) {
      pages.add(Pair.of(baseUrl + index, index));
    }
    return pages;
  }
}
